USE [BMIG_Mensual_POST_CADENA]
GO

 -- creating the store procedure
IF EXISTS (SELECT name  FROM   sysobjects WHERE  name = N'[dbo].[WASP_M0014_SEGURO_CESANTIA]' AND type = 'P')
    DROP PROCEDURE [dbo].[WASP_M0014_SEGURO_CESANTIA]
GO


CREATE PROCEDURE [dbo].[WASP_M0014_SEGURO_CESANTIA]
AS

BEGIN

		CREATE TABLE dbo.sc_segcesa (ppsuc int, 
									 ppcta numeric,
									 ppoper numeric, 
									 cod_seg int,
									 val_seg float)
END


BEGIN
		INSERT INTO dbo.sc_segcesa 
		select ppsuc, ppcta, ppoper, cod_seg1, val_seg1
		from dbo.sc_seg where cod_seg1 = 105 

		INSERT INTO dbo.sc_segcesa 
		select ppsuc, ppcta, ppoper, cod_seg2, val_seg2
		from dbo.sc_seg  where cod_seg2 = 105 

		INSERT INTO dbo.sc_segcesa 
		select ppsuc, ppcta, ppoper, cod_seg3, val_seg3
		from dbo.sc_seg  where cod_seg3 = 105 

		INSERT INTO dbo.sc_segcesa 
		select ppsuc, ppcta, ppoper, cod_seg4, val_seg4
		from dbo.sc_seg  where cod_seg4 = 105 

		INSERT INTO dbo.sc_segcesa 
		select ppsuc, ppcta, ppoper, cod_seg5, val_seg5
		from dbo.sc_seg  where cod_seg5 = 105 

		INSERT INTO dbo.sc_segcesa 
		select ppsuc, ppcta, ppoper, cod_seg6, val_seg6
		from dbo.sc_seg  where cod_seg6 = 105 

		INSERT INTO dbo.sc_segcesa 
		select ppsuc, ppcta, ppoper, cod_seg7, val_seg7
		from dbo.sc_seg  where cod_seg7 = 105 

		INSERT INTO dbo.sc_segcesa 
		select ppsuc, ppcta, ppoper, cod_seg8, val_seg8
		from dbo.sc_seg  where cod_seg8 = 105 

		INSERT INTO dbo.sc_segcesa 
		select ppsuc, ppcta, ppoper, cod_seg9, val_seg9
		from dbo.sc_seg  where cod_seg9 = 105 
END